using System.Collections.Generic;
using System.Web.Http;

namespace MvcApp.Controllers
{
    public class PositionsController : ControllerBase<Position, PositionFilter>
    {
        public PositionsController(IService<Position, PositionFilter> service)
            : base(service)
        {
        }

        [ActionName("GetAutocomplete")]
        public AutoComplete<AutoCompleteItem> GetAutocomplete(string query)
        {
            var autoComplete = new AutoComplete<AutoCompleteItem> { query = query, suggestions = new List<AutoCompleteItem>() };
            var lst = _service.Get(new PositionFilter{Title = query}).Select(o => new AutoCompleteItem { data = o.Id.ToString(), value = o.Title });
            autoComplete.suggestions.AddRange(lst);
            return autoComplete;
        }
    }
}